"""server模块api"""

from src.mod import Wfs
from src.schema import Schema
from flask import Response, request
from .origin import capture_exception
from src.api.origin import basic_decorator
from flask_jwt_extended import jwt_required
from src.apps.system import Info as ServerInfo
from src.apps.hosting.basic_info import all_count
from src.core.nodes.manage import compile_status


@basic_decorator(result=False, multi_nodes=True)
def reaload(user, ):
    """服务器实时负载"""
    return ServerInfo.reaload()


@basic_decorator(multi_nodes=True)
def wfs(user,):
    """"""
    schema = Schema.Wfs(**request.get_json(force=True))
    return getattr(Wfs(), schema.method)(schema.path)


@basic_decorator(result=False, multi_nodes=True)
def basic_info(user, ):
    """节点基础信息（除系统负载外的所有信息）"""
    result = {
        "realtime": ServerInfo.realtime(),
        "fm_occ_space": ServerInfo.fm_occ_space(),
        "hosting_count": all_count(),
        "system_info": ServerInfo.system_info(),
        "compile_status": compile_status(),
    }
    from src.core.variables.status import SUCCESS_CODE_CUSTOMIZE
    return SUCCESS_CODE_CUSTOMIZE(result)